﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XMM.Controls.Library
{
    /// <summary>
    /// Interaktionslogik für Holster_DiskMedia.xaml
    /// </summary>
    public partial class Holster_DiskMedia : UserControl
    {
        /// <summary>
        /// Currently selected DiskMedia() or null.
        /// </summary>
        public Objects.DiskMedia SelectedDisk {get;set;}

        /// <summary>
        /// Currently selected DiskMedia-Database-ID.
        /// </summary>
        public int SelectedMediaID
        {
            get
            {
                if (SelectedDisk != null && SelectedDisk.DiskMediaID != 0)
                {
                    return SelectedDisk.DiskMediaID;
                }

                return 0;
            }
        }

        /// <summary>
        /// Initialize a new DiskMedia-Holster-Control.
        /// </summary>
        public Holster_DiskMedia()
        {
            InitializeComponent();

            SelectedDisk = null;
        }

        /// <summary>
        /// Assign new DiskMedia()-Object.
        /// </summary>
        /// <param name="oNewDisk"></param>
        public void setDiskMedia(Objects.DiskMedia oNewDisk)
        {
            SelectedDisk = oNewDisk;
        }

        /// <summary>
        /// Set status-icon.
        /// </summary>
        public void setStatusIcon()
        {
            if (SelectedDisk != null && SelectedDisk.DiskMediaID != 0)
            {
                imgMediaIcon.Source = new BitmapImage(new Uri(@"../../images/bin/disk.png", UriKind.Relative));
                imgMediaIcon.ToolTip = SelectedDisk.MediaName + " (" + SelectedDisk.MediaDate.ToShortDateString() + ")";
                imgDiskMediaStatus.Source = new BitmapImage(new Uri(@"../../images/bin/save.png", UriKind.Relative));
            }
            else
            {
                imgMediaIcon.Source = new BitmapImage(new Uri(@"../../images/bin/cdrom_64.png", UriKind.Relative));
                imgMediaIcon.ToolTip = "Separater Datenträger";
            }
        }

        private void btnEditDiskMedia_Click(object sender, RoutedEventArgs e)
        {
            Dialoges.Library.EditDiskMedia dlgDiskEditor = new Dialoges.Library.EditDiskMedia(this);
            if(SelectedDisk != null && SelectedDisk.DiskMediaID != 0)
            {
                dlgDiskEditor.SelectedDiskMedia = SelectedDisk;
            }
            dlgDiskEditor.ShowDialog();
        }
    }
}
